package com.zhangtai.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;

@EnableAsync
@Configuration
public class ELKThreadPool {
    @Bean("Log")
    public Executor taskExecutor() {
        ThreadPoolTaskExecutor pool = new ThreadPoolTaskExecutor();
        pool.setCorePoolSize(16); //核心线程数
        pool.setQueueCapacity(16); //队列数
        pool.setMaxPoolSize(24); //最大线程数
        pool.setWaitForTasksToCompleteOnShutdown(true);
        pool.setThreadNamePrefix("elk_log");
        pool.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); //线程池拒绝策略，谁提交就给谁执行
//        pool.setAllowCoreThreadTimeOut(true); //允许核心线程销毁
        return pool;
    }

    @Bean("Neusoft")
    public Executor taskNeusoftExecutor() {
        ThreadPoolTaskExecutor pool = new ThreadPoolTaskExecutor();
        pool.setCorePoolSize(16); //核心线程数
        pool.setQueueCapacity(16); //队列数
        pool.setMaxPoolSize(24); //最大线程数
        pool.setWaitForTasksToCompleteOnShutdown(true);
        pool.setThreadNamePrefix("neusoft");
        pool.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); //线程池拒绝策略，谁提交就给谁执行
//        pool.setAllowCoreThreadTimeOut(true); //允许核心线程销毁
        return pool;
    }
}
